﻿// Copyright (c) 2012 - 2021 Jared Zheng <jaredz at outlook dot com>
// Buddha Framework is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Create : 2012-12-01 version 0.1 Jared Zheng <jaredz at outlook dot com>
// Update : 2021-03-19 version 4.0.0 Jared Zheng <jaredz at outlook dot com>

#ifndef __COMMON_SERVER_H__
#define __COMMON_SERVER_H__

#pragma once

#include "object.h"
#include "ServerConfig.h"
#include "ServerInfo.h"

///////////////////////////////////////////////////////////////////////////////////////////////////////////
// 框架接口
class NOVTABLE ICommonFrame ABSTRACT : public CComponent
{
public:
    // CComponent
    //virtual UInt   Command(PCXStr pszCMD, uintptr_t utParam) PURE;
    //virtual UInt   Update(void) PURE;

    // 初始化服务
    virtual UInt   Init(CEventHandler& EventHandlerRef, CServerConfig& ConfigRef, UInt uRank) PURE;
    // 结束服务
    virtual void   Exit(void) PURE;
    // 开启服务
    virtual bool   Start(void) PURE;
    // 停止服务
    virtual void   Stop(bool bUnlink = true) PURE;

    virtual CServerConfig&    GetConfig(void) PURE;
    virtual CEventHandlerPtr& GetMgrHandler(void) PURE;
    virtual CNetworkPtr&      GetNetworkPtr(void) PURE;
    virtual CFileLogPipe&     GetFileLog(void) PURE;
    virtual CSignalEvent&     GetSignalEvent(void) PURE;
    virtual SERVER_DATA&      GetData(void) PURE;
    // 获取集群统计信息
    virtual SERVER_CLUSTER&   GetCluster(UInt uRank, bool bLocal = true) PURE;
};
typedef CTRefCountPtr<ICommonFrame> CFramePtr;

///////////////////////////////////////////////////////////////////////////////////////////////////////////
// 业务接口
class NOVTABLE ICommonRoutine ABSTRACT : public CObject
{
public:
    // 初始化
    virtual bool Load(ICommonFrame* pFrame, UInt uRank) PURE;
    // 结束
    virtual void Unload(void) PURE;
    // 开启
    virtual bool Start(void) PURE;
    // 更新
    virtual bool Update(void) PURE;
    // 停止
    virtual void Stop(void) PURE;
};
typedef CTRefCountPtr<ICommonRoutine> CRoutinePtr;

///////////////////////////////////////////////////////////////////////////////////////////////////////////
// CServerSystem : CSubSystem
DECLARE_UUID( CServerSystem, {8713909F-967C-55DE-AAE9-F92CAE0E2710} )

#endif // __COMMON_SERVER_H__
